package businesslogic.importbl;

import java.rmi.RemoteException;
import java.util.ArrayList;

import businesslogic.clientbl.Client;
import businesslogic.stockbl.GoodsManager;
import po.GoodsPO;
import po.ImportGoodsPO;
import po.ImportPO;
import po.ImportReturnPO;
import utility.TimePeriod;
import vo.ClientVO;
import vo.GoodsVO;
import vo.ImportGoodsVO;
import vo.ImportInfoVO;
import vo.ImportVO;
import data.importdata.ImportDataController;

public class Import {
	private Client client;
	private ImportList importList;
	
	public ArrayList<ClientVO> showClientList() {
		// TODO Auto-generated method stub
		return client.getClientVOList();
	}

	public ArrayList<GoodsVO> showGoodsList() {
		// TODO Auto-generated method stub
		return null;
	}

	public boolean addClient(ClientVO vo) {
		// TODO Auto-generated method stub
		return false;
	}

	public boolean addGoods(String loc, int number, double unitPrice, String notes) {
		// TODO Auto-generated method stub
		GoodsPO goods= new GoodsManager().findGoods(loc);
		if (true) {
			return false;
		}
		importList.addOneGoods(goods, number, unitPrice, notes);
		return true;
	}

	public boolean addOtherInfo(ImportInfoVO vo) {
		// TODO Auto-generated method stub
		return false;
	}

	public ArrayList<ImportVO> showImport() {
		// TODO Auto-generated method stub
		ArrayList<ImportVO> vos = new ArrayList<ImportVO>();
		ArrayList<ImportPO> pos = new ImportDataController().getImportList();
		for (int i = 0; i < pos.size(); i++) {
			vos.add(transformImportPO(pos.get(i)));
		}
		return vos;
	}

	public boolean importReturn(int loc) {
		// TODO Auto-generated method stub
		return false;
	}

	public double getTotal() {
		// TODO Auto-generated method stub
		return 0;
	}

	public boolean creatImport() {
		// TODO Auto-generated method stub
		return false;
	}

	public void endImport() {
		// TODO Auto-generated method stub
		
	}

	
	//内部方法
	
	//将po转换成vo
	private ImportVO transformImportPO(ImportPO po){
		ImportVO vo = new ImportVO();
		vo.setClient(po.getClient().getName());
		vo.setGoodsVOs(transformImportGoodsVO(po.getGoodsPOs()));
		vo.setNotes(po.getNotes());
		vo.setOperator(po.getOperator());
		vo.setReceiptsID(po.getReceiptsID());
		vo.setStorehouse(po.getStorehouse());
		vo.setTotal(po.getTotal());
		
		return vo;
	}
	
	private ArrayList<ImportGoodsVO> transformImportGoodsVO(ArrayList<ImportGoodsPO> pos){
		ArrayList<ImportGoodsVO> vos = new ArrayList<ImportGoodsVO>();
		//为每个po进行转换
		for (int i = 0; i < pos.size(); i++) {
			ImportGoodsVO vo = new ImportGoodsVO();
			ImportGoodsPO po = pos.get(i);
			vo.setModel(po.getModel());
			vo.setName(po.getName());
			vo.setNotes(po.getNotes());
			vo.setNum(po.getNum());
			vo.setNumber(po.getNumber());
			vo.setSum(po.getSum());
			vo.setUnitPrice(po.getUnitPrice());
			//添加
			vos.add(vo);
		}
		
		return vos;
	}
	
	public boolean removeClient() throws RemoteException {
		// TODO Auto-generated method stub
		return false;
	}


	public boolean removeGoods(int loc) throws RemoteException {
		// TODO Auto-generated method stub
		return false;
	}
	
	public ArrayList<ImportPO> multipleConditionFindSales(TimePeriod period,String goodsName,String clientId,String salesman,String storehouse){
		return null;
	}
	
	public ArrayList<ImportReturnPO> multipleConditionFindSalesReturn(TimePeriod period,String goodsName,String clientId,String salesman,String storehouse){
		return null;
	}
}
